﻿using System;
using System.Collections.Generic;
using System.Windows.Media;
using Elca.MvvmHelpers;

namespace ULSDeobfuscator {
    public class ColorRule : BaseNotifyableObject {

        /// <summary>
        /// Special value to mean any w3wp
        /// </summary>
        public const string AnyWorkerProcess = "Any w3wp";
        /// <summary>
        /// String prefix to compare a w3wp process against, if user chose to match any worker process
        /// </summary>
        public const string WorkerProcessPrefix = "w3wp";

        private string _name;
        public string Name {
            get { return _name; }
            set {
                if (_name != value) {
                    _name = value;
                    OnPropertyChanged("Name");
                }
            }
        }

        public List<string> Processes  { get; set; }
        public List<string> Areas      { get; set; }
        public List<string> Categories { get; set; }
        public List<string> Levels     { get; set; }
        public List<string> EventIDs   { get; set; }

        public bool IsSystemDefined { get; set; }

        private string _message;
        public string Message {
            get { return _message; }
            set {
                if (_message != value) {
                    _message = value;
                    OnPropertyChanged("Message");
                }
            }
        }

        private string _correlation;
        public string Correlation {
            get { return _correlation; }
            set {
                if (_correlation != value) {
                    _correlation = value;
                    OnPropertyChanged("Correlation");
                }
            }
        }

        private bool _isMultiLine;
        public bool IsMultiLine {
            get { return _isMultiLine; }
            set {
                if (_isMultiLine != value) {
                    _isMultiLine = value;
                    OnPropertyChanged("IsMultiLine");
                }
            }
        }

        private bool _hasAnnotation;
        public bool HasAnnotation {
            get { return _hasAnnotation; }
            set {
                if (_hasAnnotation != value) {
                    _hasAnnotation = value;
                    OnPropertyChanged("HasAnnotation");
                }
            }
        }
        private bool _isPersistent;
        public bool IsPersistent {
            get { return _isPersistent; }
            set {
                if (_isPersistent != value) {
                    _isPersistent = value;
                    OnPropertyChanged("IsPersistent");
                }
            }
        }


        private Color? _foregroundColor;
        public Color? ForegroundColor {
            get { return _foregroundColor; }
            set {
                if (_foregroundColor != value) {
                    _foregroundColor = value;
                    OnPropertyChanged("ForegroundColor");
                }
            }
        }

        private Color? _backgroundColor;
        public Color? BackgroundColor {
            get { return _backgroundColor; }
            set {
                if (_backgroundColor != value) {
                    _backgroundColor = value;
                    OnPropertyChanged("BackgroundColor");
                }
            }
        }


        public ColorRule() {
            Processes = new List<string>();
            Areas = new List<string>();
            Categories = new List<string>();
            Levels = new List<string>();
            EventIDs = new List<string>();
        }

        public ColorRule Clone() {

            ColorRule newCR = new ColorRule();
            CopyTo(newCR);

            return newCR;
        }

        public void CopyTo(ColorRule destination) {
            destination.Name = Name;
            destination.Message = Message;
            destination.Correlation = Correlation;
            destination.IsMultiLine = IsMultiLine;
            destination.IsPersistent = IsPersistent;
            destination.HasAnnotation = HasAnnotation;

            destination.Processes.Clear();
            destination.Processes.AddRange(Processes);
            destination.Areas.Clear();
            destination.Areas.AddRange(Areas);
            destination.Categories.Clear();
            destination.Categories.AddRange(Categories);
            destination.Levels.Clear();
            destination.Levels.AddRange(Levels);
            destination.EventIDs.Clear();
            destination.EventIDs.AddRange(EventIDs);

            destination.ForegroundColor = ForegroundColor;
            destination.BackgroundColor = BackgroundColor;
        }
    }
}
